package com.servlet;

import com.bean.Member;
import com.common.Cache;
import com.dao.MemberMapper;
import com.service.core.SpringBeanUtil;
import com.util.DESUtils;
import com.util.QRcodeUtil;
import com.util.StringUtil;
import org.apache.log4j.Logger;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLDecoder;

/**
 * Created by lvjianqing on 2017/7/27.
 */
public class QrcodeServlet extends HttpServlet {
    Logger log = Logger.getLogger(QrcodeServlet.class);

    public void init() throws ServletException {
    }

    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        try {
            //二维码规格
            int size = StringUtil.String2Integer(req.getParameter("size"), 600);
            String content = req.getParameter("content");
            String qrStr = "暂时无法提供服务";
            if (StringUtil.isNotEmpty(content)) {
                qrStr = content;
            }
            byte[] b = QRcodeUtil.write(qrStr, size, size);
            resp.reset();
            resp.setHeader("Content-Type", "image/jped");
            resp.getOutputStream().write(b);
            resp.getOutputStream().flush();
            resp.getOutputStream().close();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
